package com.xbao.controller;

import com.xbao.core.component.page.Pagination;
import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.req.ClsReq;
import com.xbao.model.req.PeriodRecordReq;
import com.xbao.model.vo.PeriodRecordTotalVo;
import com.xbao.model.vo.PeriodRecordVo;
import com.xbao.service.PeriodRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/10/13.
 */
@Api(value = "/periodrecord", tags = "periodrecord")
@RequestMapping(value = "periodrecord")
@Controller
@EnableAutoConfiguration
public class PeriodRecordController extends BaseController {

    @Resource
    private PeriodRecordService recordService;

    /**
     * @param reqCommRequest
     * @return
     */
    @ApiOperation(value = "nextPeriodRecord", notes = "nextPeriodRecord")
    @RequestMapping(value = "/nextrecord",method = RequestMethod.POST)
    @ResponseBody
    public CommResult nextPeriodRecord(@RequestBody CommRequest<PeriodRecordReq> reqCommRequest) {
        PeriodRecordVo vo = recordService.nextPeriodRecordOfClss(reqCommRequest.getData().getCid(), System.currentTimeMillis());
        return new CommResult<PeriodRecordVo>(vo);

    }
    @ApiOperation(value = "recordlistOfCls", notes = "recordlistOfCls")
    @RequestMapping(value = "/recordlistOfCls",method = RequestMethod.POST)
    @ResponseBody
    public CommResult recordlistOfCls(@RequestBody CommRequest<ClsReq> reqCommRequest) {
        List<PeriodRecordVo> vo = recordService.queryRecordOfCls(reqCommRequest.getData());
        return new CommResult<List<PeriodRecordVo>>(vo);

    }


    @ApiOperation(value = "delete", notes = "delete")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
      @ResponseBody
      public CommResult delete(@RequestBody CommRequest<PeriodRecordReq> reqCommRequest) {
        PeriodRecordVo vo = recordService.nextPeriodRecordOfClss(reqCommRequest.getData().getCid(), System.currentTimeMillis());
        return new CommResult<PeriodRecordVo>(vo);

    }
    @ApiOperation(value = "add", notes = "add")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public CommResult add(@RequestBody CommRequest<PeriodRecordReq> reqCommRequest) {
        PeriodRecordVo vo = recordService.nextPeriodRecordOfClss(reqCommRequest.getData().getCid(), System.currentTimeMillis());
        return new CommResult<PeriodRecordVo>(vo);

    }
    @ApiOperation(value = "noFinishRecords", notes = "noFinishRecords")
    @RequestMapping(value = "/nofinishrecord",method = RequestMethod.POST)
    @ResponseBody
    public CommResult<Pagination<PeriodRecordVo>> noFinishRecords(@RequestBody CommRequest<PeriodRecordReq> reqCommRequest) {
        Pagination<PeriodRecordVo> vos= recordService.noFinishRecords(null, null);
        return new CommResult<Pagination<PeriodRecordVo>>(vos);
    }

    /**
     * @param reqCommRequest
     * @return
     */
    @ApiOperation(value = "periodRecordTotal", notes = "periodRecordTotal")
    @RequestMapping(value = "/periodTotal",method = RequestMethod.POST)
    @ResponseBody
    public CommResult<PeriodRecordTotalVo> periodRecordTotal(@RequestBody CommRequest<PeriodRecordReq> reqCommRequest) {
        Long begintime=reqCommRequest.getData().getBegintime();
        Long endtime=reqCommRequest.getData().getEndtime();
        Long orgid=reqCommRequest.getData().getOrgid();
        PeriodRecordTotalVo vo= recordService.queryPeriodREcordTotal(begintime, endtime,orgid);
        return new CommResult<PeriodRecordTotalVo>(vo);
    }


    @ApiOperation(value = "check", notes = "check")
    @RequestMapping(value = "/check",method = RequestMethod.POST)
    @ResponseBody
    public CommResult check(@RequestBody CommRequest<PeriodRecordReq> reqCommRequest) {
        recordService.checkRecord(reqCommRequest.getData());
        return result();
    }





}
